
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <title>添加用户</title>

</head>
<body class="mybody">

<jsp:include page="theTopMenuAdmin.jsp" />

<div class="container-fluid">
    <div class="row">




        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="alert alert-success">


                                <div >
        <h3 style="text-align: center">添加用户信息</h3>
        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3" />

        <div id="add_user">
            <div class="form-group same-line">
                <label for="user_loing_name"><b style="color: red">*&nbsp</b>登录名或账号：</label>
                <input type="text" id="user_loing_name" class="form-control edit" placeholder="请输入登录名或账号" v-model="user_loing_name">
            </div>

            <div class="form-group same-line-left">
                <label for="user_loing_passwd"><b style="color: red">*&nbsp</b>登录密码：</label>
                <input type="text" id="user_loing_passwd" class="form-control edit" placeholder="请输入登录密码" v-model="user_loing_passwd">
            </div>

            <div class="form-group same-line-left">
                <label for="user_level"><b style="color: red">*&nbsp</b>用户类型：</label>
                <select class="form-control edit" title="请选择" id="user_level" data-live-search="true" data-size="5">
                    <option value="" disabled selected hidden>请选择</option>
                    <option value="0">管理员</option>
                    <option value="1">教师</option>
                    <option value="2">学生</option>
                </select>
            </div>

            <div class="form-group same-line">
                <label for="user_name">用户名：</label>
                <input type="text" id="user_name" class="form-control edit" placeholder="请输入用户名" v-model="user_name">
            </div>

            <div class="form-group same-line-left">
                <label for="user_sex">用户性别：</label>
                <select class="form-control edit" title="请选择" id="user_sex" data-live-search="true" data-size="5">
                    <option value="" disabled selected hidden>请选择</option>
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>

            <div class="form-group same-line-left">
                <label for="user_email">用户邮箱：</label>
                <input type="email" id="user_email" class="form-control edit" placeholder="请输入用户邮箱" v-model="user_email">
            </div>

            <div class="form-group same-line">
                <label for="user_brithday">生日：</label>
                <input type="date" id="user_brithday" class="form-control edit" placeholder="请输入用户生日" v-model="user_brithday">
            </div>

            <div class="form-group same-line-left">
                <label for="user_address">用户地址：</label>
                <input type="text" id="user_address" class="form-control edit" placeholder="请输入地址" v-model="user_address">
            </div>

            <div class="form-group same-line-left">
                <label for="user_phone">用户座机：</label>
                <input type="text" id="user_phone" class="form-control edit" placeholder="请输入用户座机" v-model="user_phone">
            </div>

            <div class="form-group same-line">
                <label for="user_tel">用户手机号：</label>
                <input type="text" id="user_tel" class="form-control edit" placeholder="请输入用户手机号" v-model="user_tel">
            </div>
        </div>

        <div class="form-group text-center same-line-clear">
            <input type="button" value="添加" class="btn btn-primary" onclick="addUser()">
            <input type="reset" value="重置" class="btn btn-danger interval" onclick="reset()">
        </div>

        <div class="text-center">
            <label id="user_null" style="color: red"></label>
        </div>

    </div>

                            </div>
                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>



<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    function reset(){
        var addUser = document.getElementById("add_user");
        var ipts = addUser.getElementsByTagName("input");
        for (var i = 0; i < ipts.length; i++){
            ipts[i].value = "";
        }
    }

    function addUser(){
        var userLoingName = $("#user_loing_name").val();
        var userLoingPasswd = $("#user_loing_passwd").val();
        var userLevel = $("#user_level").val();

        var userName = $("#user_name").val();
        var userSex = $("#user_sex").val();
        var userEmail = $("#user_email").val();
        var userBrithday = $("#user_brithday").val();
        var userAddress = $("#user_address").val();
        var userPhone = $("#user_phone").val();
        var userTel = $("#user_tel").val();

        var userNull = document.getElementById("user_null");

        if ($.isEmptyObject(userLoingName)){
            userNull.innerHTML = "登录名或账号不能为空";
            return false;
        }else if ($.isEmptyObject(userLoingPasswd)){
            userNull.innerHTML = "密码不能为空";
            return false;
        }else if ($.isEmptyObject(userLevel)){
            userNull.innerHTML = "用户类型不能为空";
            return false;
        }else {
            userNull.innerHTML = "";
        }

        if ($.isEmptyObject(userName)){
            userName = null;
        }
        if ($.isEmptyObject(userSex)){
            userSex = null;
        }
        if ($.isEmptyObject(userEmail)){
            userEmail = null;
        }
        if ($.isEmptyObject(userBrithday)){
            userBrithday = null;
        }
        if ($.isEmptyObject(userAddress)){
            userAddress = null;
        }
        if ($.isEmptyObject(userPhone)){
            userPhone = null;
        }
        if ($.isEmptyObject(userTel)){
            userTel = null;
        }

        var postUrl = "${pageContext.request.contextPath}/member/userRegister";
        var str = {
            "userLoginName": userLoingName,
            "userLoginPwd": userLoingPasswd,
            "userLevel": userLevel,
            "userName": userName,
            "userSex": userSex,
            "userEmail": userEmail,
            "userBrithday": userBrithday,
            "userAddress": userAddress,
            "userPhone": userPhone,
            "userTel": userTel
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    userNull.innerHTML = data.msg;
                    alert("添加用户出错")
                }else {
                    //alert("添加用户成功")
                    location.href = "${pageContext.request.contextPath}/adminStrationManagement";
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>